package com.example.fresh_fruit.service.Impl;

import com.example.fresh_fruit.dto.OrderDto;
import com.example.fresh_fruit.entity.Head;
import com.example.fresh_fruit.entity.Orders;
import com.example.fresh_fruit.mapper.HeadMapper;
import com.example.fresh_fruit.mapper.OrdersMapper;
import com.example.fresh_fruit.service.OrdersService;
import com.example.fresh_fruit.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :飞天の鱼
 * @date : 2022/8/22 21:57
 */
@Service
public class OrdersServiceImpl implements OrdersService {

    @Autowired
    private OrdersMapper ordersMapper;

    @Autowired
    private HeadMapper headMapper;

    @Override
    public List<Orders> selectAll() {
        return ordersMapper.selectAll();
    }

    @Override
    public int insertOders(OrderDto orderDto) {
        return 0;
    }

    @Override
    public int cheakOrders(Orders orders) {
        Integer headId = orders.getHeadId();
        Head head = headMapper.findById(headId);
        if (head==null){
            Result.fail("无此团长");
            return 1;
        }else{
            Integer headState=head.getState();
            if (headState!=0){
                Result.fail("团长不干了");
                return 2;
            }
        }
        Result.ok("一切正常");
        //团长状态正常
        return 0;
    }

    @Override
    public Integer findMaxId() {
        return null;
    }
}
